var express = require('express');
var db = require('../../../tools/database')
var router = express.Router();

// 提交商品信息
router.use(function (req, res, next) {
	let form = JSON.parse(req.body.formData)
	let file_hw_ratio = req.body.file_hw_ratio
	let itemID = req.body.itemID
	let sql = 'UPDATE Items SET ' +
		  `ItemName=?, ItemPrice=?, ItemDescription=?, ItemOldNewRate=?, CoverFileName=?, DeliverByPost=?, ` +
		  `DeliverByFace=?, DeliverNoNeed=?, Remarks=?, CoverFileHWRatio=?` +
		  `WHERE ItemID=?`
	let options = [form.itemName, form.itemPrice, form.itemDescription, form.itemOldNewRate
		, form.coverFileName, Boolean(form.hasOwnProperty('deliverByPost')),  Boolean(form.hasOwnProperty('deliverByFace')), Boolean(form.hasOwnProperty('deliverNoNeed'))
		, form.remarks, file_hw_ratio, itemID]

	db.queryRespond(sql, options, res)
});

module.exports = router;